package com.group.eams.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.*;
import com.group.eams.pojo.entity.AssetDispose;
import com.group.eams.pojo.entity.AssetDispose;
import com.group.eams.pojo.entity.AssetDispose;
import com.group.eams.pojo.vo.AssetDisposeListVo;
import com.group.eams.pojo.vo.DisposeFixedDetailListVo;
import com.group.eams.pojo.vo.DisposeFixedListVo;
import com.group.eams.service.AssetDisposeService;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 资产处置表(AssetDispose)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/assetDispose")
public class AssetDisposeController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetDisposeService assetDisposeService;

    /**
     * 查询资产处置信息列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result<List<AssetDisposeListVo>> findAssetDisposeByWhere(AssetDisposeQueryDto assetDisposeQueryDto) {
        Page<AssetDisposeListVo> disposeListVoPage = assetDisposeService.findAssetDisposeByWhere(assetDisposeQueryDto);
        return Result.buildSuccess(disposeListVoPage.getTotal(),disposeListVoPage.getRecords());
    }

    /**
     * 按id查询资产处理信息
     */
    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public Result<AssetDispose> find(@RequestParam Long id) {
        AssetDispose assetDispose = assetDisposeService.getById(id);
        return Result.buildSuccess(assetDispose);
    }

    /**
     * 查询所有资产处置信息
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result<List<AssetDispose>> findAll(){
        List<AssetDispose> assetDisposeList = assetDisposeService.list();
        return Result.buildSuccess(assetDisposeList);
    }

    /**
     * 添加资产处置信息
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Object> add(@RequestBody AssetDispose assetDispose) {
        boolean result = assetDisposeService.save(assetDispose);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改资产处置信息
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result<Object> update(@RequestBody AssetDispose assetDispose){
        boolean result = assetDisposeService.updateById(assetDispose);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量添加资产处置信息
     */
    @RequestMapping(value = "/batchAdd",method = RequestMethod.POST)
    public Result<Object> batchAdd(@RequestBody List<AssetDispose> assetDisposes){
        boolean result = assetDisposeService.saveBatch(assetDisposes);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量修改资产处置信息
     */
    @RequestMapping(value = "/batchUpdate",method = RequestMethod.POST)
    public Result<Object> batchUpdate(@RequestBody List<AssetDispose> assetDisposes){
        boolean result = assetDisposeService.updateBatchById(assetDisposes);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量移除资产处置信息
     */
    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    public Result<Object> batchRemove(@RequestBody List<Long> ids){
        boolean result = assetDisposeService.removeByIds(ids);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 查询所有资产信息
     */
    @RequestMapping(value = "/findDisposeFixed",method = RequestMethod.GET)
    public Result<List<DisposeFixedListVo>> findDisposeFixed(FixedAssetQueryDto fixedAssetQueryDto){
        Page<DisposeFixedListVo> disposeFixedListVoPage = assetDisposeService.findDisposeFixedByWhere(fixedAssetQueryDto);
        return Result.buildSuccess(disposeFixedListVoPage.getTotal(), disposeFixedListVoPage.getRecords());
    }

    /**
     * 根据选择的id查询资产
     */
    @RequestMapping(value = "/addDisposeFixedDetail",method = RequestMethod.POST)
    public Result<List<DisposeFixedDetailListVo>> addDisposeFixedDetail(@RequestBody AssetPartDto assetPartDto){
        Page<DisposeFixedDetailListVo> disposeFixeDetaildListVoPage = assetDisposeService.addDisposeFixedDetail(assetPartDto);
        return Result.buildSuccess(disposeFixeDetaildListVoPage.getTotal(), disposeFixeDetaildListVoPage.getRecords());
    }

    /**
     * 按申请单号查询资产处理表下的所有资产信息
     */
    @RequestMapping(value = "/findDisposeFixedDetail",method = RequestMethod.GET)
    public Result<List<DisposeFixedDetailListVo>> findDisposeFixedDetail(ApplyNumFixedAssetQueryDto applyNumFixedAssetQueryDto){
        Page<DisposeFixedDetailListVo> disposeFixeDetaildListVoPage = assetDisposeService.findDisposeFixedDetail(applyNumFixedAssetQueryDto);
        return Result.buildSuccess(disposeFixeDetaildListVoPage.getTotal(), disposeFixeDetaildListVoPage.getRecords());
    }

    /**
     * 根据申请单号和assetId删除
     */
    @RequestMapping(value = "/deleteByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchDeleteIdsDto batchDeleteIdsDto){
        int result = assetDisposeService.deleteByApplicationNum(batchDeleteIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    
    /**
     * 根据申请单号和assetId修改
     */
    @RequestMapping(value = "/updateByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchUpdateIdsDto<AssetDispose> batchUpdateIdsDto){
        int result = assetDisposeService.updateByApplicationNum(batchUpdateIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 根据申请单号查询
     */
    @RequestMapping(value = "/findByNum",method = RequestMethod.GET)
    public Result<AssetDispose> findByNum(@RequestParam String applicationNum) {
        AssetDispose assetDispose = assetDisposeService.findDisposeByNum(applicationNum);
        return Result.buildSuccess(assetDispose);
    }
}

